package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsOrder;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {
    /**
     * 查询每日订单数量
     * @return
     */
    @Select("   select DATE_FORMAT(a.add_time, \"%Y-%m-%d\") as dayStr, " +
            "   count(*) as cnts, " +
            "   sum(actual_price) as amts " +
            "   from dts_order a " +
            "   where a.deleted=0 " +
            "   group by DATE_FORMAT(a.add_time, \"%Y-%m-%d\") ")
    public List<DayStatis> staticsIncresOrderCnt();


    /**
     * 日期和对应的订单总额, 订单笔数
     * @return
     */
    @Select("SELECT" +
            "   DATE_FORMAT(add_time,\"%Y-%m-%d\") dayStr , count(*) AS cnts , sum(goods_price) as amts" +
            "   FROM" +
            "   dts_order " +
            "   where deleted=0" +
            "   GROUP BY DATE_FORMAT(add_time,\"%Y-%m-%d\")")
    public List<DayStatis> IncresOrdercnt();


    /**
     * 按照分类, 统计每个分类中商品的销售额
     */
    @Select("   select d.`name`, sum(a.price) as value " +
            "   from dts_order_goods a " +
            "   left join dts_order b on a.order_id = b.id " +
            "   left join dts_goods c on a.goods_id = c.id  " +
            "   left join dts_category d on c.category_id = d.id " +
            "   where a.deleted=0 and b.deleted=0 and d.`name` is not null " +
            "   group by d.`name`")
    public List<CategorySellAmts> categorySell();

}
